package org.ayachinene.leetcode.problems;

public class P2303 {

    static class Solution {
        public double calculateTax(int[][] brackets, int income) {
            if (income == 0)
                return 0;

            double tax = 0;
            int i = 0;
            while (i < brackets.length && brackets[i][0] < income) {
                tax += (brackets[i][0] - (i > 0 ? brackets[i - 1][0] : 0)) * brackets[i][1];
                i++;
            }
            tax += (income - (i > 0 ? brackets[i - 1][0] : 0)) * brackets[i][1];
            return tax / 100;
        }
    }
}
